<template>
  <div class="app-container" v-loading="loading">
    <!-- <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="72px"
    >
      <el-form-item label="门店名称" prop="branchName">
        <el-input
          v-input-restrict
          v-model="queryParams.branchName"
          placeholder="请输入门店名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          v-preventReClick
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          v-preventReClick
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-preventReClick
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->
    <div>
      <div></div>
    </div>
    <!-- 添加或修改岗位对话框 -->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :title="title" :visible.sync="open"
      width="550px" append-to-body>
      <el-form @submit.native.prevent ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="门店类型名称" prop="tagName">
          <el-input :disabled="form.tagId == 1" v-input-restrict show-word-limit maxlength="20" style="width: 95%"
            v-model="form.tagName" placeholder="请输入门店类型名称" />
        </el-form-item>

        <!-- <el-form-item label="封面" prop="branchPic">
          <div>
            
            <div
              v-if="form.branchPic"
              class="upload-head"
              @click="editCropper()"
            >
              <img v-bind:src="form.branchPic" class="cover" />
            </div>
            <div v-else class="upload-head" @click="editCropper()">
              <div>
                <img src="@/assets/images/add.png" class="add" alt="" />
              </div>
              <div>上传图片</div>
            </div>

            <div class="uploadTipbottom">
              建议图片比例16:10，支持jpg、png格式，图片小于5M
            </div>
          </div>

          <vuecut
            :w="320"
            :h="200"
            :url="form.branchPic"
            @coverResult="coverResult"
            title="图片上传"
            :open.sync="vuecutshow"
          ></vuecut>
        </el-form-item> -->

        <el-form-item label="简介" prop="introduction">
          <el-input v-input-restrict style="width: 95%" maxlength="500" show-word-limit
            :autosize="{ minRows: 5, maxRows: 8 }" v-model="form.introduction" type="textarea"
            placeholder="请输入门店类型简介" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="open = false">取 消</el-button>
        <el-button v-preventReClick type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 列表 -->
    <div class="list flex" v-infinite-scroll="getMore" infinite-scroll-immediate="false">
      <el-empty v-if="postList.length == 0" style="margin: 0 auto" description="暂无标签"></el-empty>
      <div :style="{
    backgroundImage: `url('${item.branchPic
        ? item.branchPic
        : require('@/assets/images/branch.png')
      }')`,
    backgroundSize: 'cover',
    backgroundRepeat: 'no-repeat',
  }" class="card rela shou" v-for="(item, index) in postList" :key="index" @click="toMajor(item)">
        <!-- 按钮组 -->
        <div class="function abso">
          <div class="iconbox" @click.stop="handleUpdate(item)">
            <img class="shou" src="@/assets/images/icon2.png" />
          </div>
          <div class="iconbox" @click.stop="HandleDetail(item)">
            <img class="shou" src="@/assets/images/icon0.png" />
          </div>
        </div>
        <div class="bottom abso">
          <div class="num">
            门店数量：{{ item.schoolNum ? item.schoolNum : 0 }}
          </div>
          <div class="content">
            {{ item.introduction }}
          </div>

          <div class="t">{{ item.tagName }}</div>
        </div>
      </div>
    </div>
    <!-- 详情弹框 -->
    <lableDetailDialog :open.sync="lableDetailOpen" :item="lableDetailItem"></lableDetailDialog>
  </div>
</template>

<script>
import lableDetailDialog from "./lableDetailDialog";
import { listPost_tag, getPost_tag, updatePost_tag } from "@/api/school/tag";
export default {
  components: { lableDetailDialog: lableDetailDialog },
  name: "Post",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      // 详情
      lableDetailItem: {},
      lableDetailOpen: false,
      //
      vuecutshow: false,
      // 遮罩层
      loading: false,
      adminloading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 总页数
      totalPage: 0,
      // 岗位表格数据
      postList: [],
      upLoadData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // level
      level: [],
      // 查询参数
      activeIndex: "",
      queryParams: {
        pageNum: 1,
        pageSize: 24,
        branchName: undefined,
        schoolId: undefined,
      },
      // 表单参数
      form: {
        createTime: undefined,
        introduction: undefined,
        remark: undefined,
        status: 0,
        tagId: undefined,
        tagName: undefined,
        updateTime: undefined,
        schoolNum: undefined,
      },
      // 表单校验
      rules: {
        tagName: [
          {
            required: true,
            message: `门店类型名称不能为空`,
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getMore() {
      this.upLoadData = [];
      if (this.postList.length >= this.total) {
        console.log("没有更多");
      } else {
        this.queryParams.pageNum++;
        if (this.queryParams.pageNum > this.totalPage) {
          console.log("没有更多了");
          return;
        }
        this.getList(true);
      }
    },

    /** 组件返回图片 */
    coverResult(e) {
      this.form.branchPic = e;
    },
    editCropper() {
      this.vuecutshow = true;
    },

    /** 查询岗位列表 */
    getList(num) {
      if (!num) {
        this.queryParams = {
          pageNum: 1,
          pageSize: 24,
        };
        this.postList = [];
      }
      this.loading = true;
      listPost_tag(this.queryParams).then((response) => {
        if (num) {
          this.upLoadData = response.rows;
          this.postList = this.postList.concat(this.upLoadData);
        } else {
          this.postList = response.rows;
        }
        this.total = response.total;
        //向上取整 总页数
        this.totalPage = Math.ceil(response.total / this.queryParams.pageSize);
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        createTime: undefined,
        introduction: undefined,
        remark: undefined,
        status: 0,
        tagId: undefined,
        tagName: undefined,
        updateTime: undefined,
        schoolNum: undefined,
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.form.schoolId = this.$store.getters.schoolId;
      this.title = `添加标签`;
    },
    /** 详情按钮操作 */
    HandleDetail(row) {
      this.lableDetailItem = row;
      this.lableDetailOpen = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.tagId || this.ids;
      getPost_tag(postId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = `编辑标签`;
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "正在处理…",
            spinner: "el-icon-loading",
            background: "rgba(255, 255, 255, 0.6)",
          });
          updatePost_tag(this.form)
            .then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              loading.close();
            })
            .catch(() => {
              loading.close();
            });
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
.list {
  max-height: calc(100vh - 289px);
  overflow-y: scroll;
  margin-top: 16px;

  .card:hover {
    .function {
      display: flex;
    }

    .bottom {
      .content {
        display: -webkit-box;
      }

      .num {
        display: -webkit-box;
      }
    }
  }

  .card {
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    width: 340px;
    height: 220px;
    border-radius: 4px;
    margin: 0 40px 40px 0;

    .shopType {
      left: 0;
      top: 0;
      border-radius: 4px 0 4px 0;
      padding: 4px 8px 4px 8px;
      color: white;
      background: rgba(0, 0, 0, 0.3);
    }

    .function {
      display: none;
      border-radius: 0px 4px 0px 4px;
      padding: 0 8px 0 8px;
      right: 0;
      top: 0;
      border-radius: 0px 4px, 0px, 4px;
      background: rgba(0, 0, 0, 0.3);

      .iconbox {
        padding: 5px 6px 5px 6px;
      }

      img {
        width: 16px;
        height: 16px;
      }
    }

    .bottom {
      bottom: 0;

      .num {
        display: none;
        background: rgba(0, 0, 0, 0.3);
        font-size: 10px;
        font-weight: 400;
        padding: 10px 10px 10px 10px;
        color: rgba(255, 255, 255, 1);
      }

      .content {
        white-space: pre-wrap;
        overflow-y: scroll; //溢出内容隐藏
        max-height: 100px;
        display: none; //特别显示模式

        width: 100%;
        background: rgba(0, 0, 0, 0.3);
        padding: 0px 10px;
        font-size: 10px;
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
      }

      .t {
        text-align: center;
        font-size: 16px;
        font-weight: 400;
        line-height: 40px;
        color: rgba(255, 255, 255, 1);
        width: 340px;
        height: 40px;
        border-radius: 0px 0px, 4px, 4px;
        background: rgba(35, 184, 112, 1);
      }
    }
  }
}

// 上传图片样式

.upload-head {
  cursor: pointer;
  position: relative;
  display: inline-block;
  width: 172px;
  height: 112px;
  border-radius: 4px;
  border: 1px dashed rgba(184, 196, 209, 1);

  .add {
    width: 29px;
    height: 29px;
    margin: 25px auto 0 auto;
  }

  div {
    font-size: 14px;
    font-weight: 400;
    color: rgba(153, 153, 153, 1);
    margin-top: 0px;
    width: 100%;
    text-align: center;
  }

  .cover {
    width: 170px;
    height: 110px;
    border-radius: 4px;
  }
}
</style>
